package com.example.utils;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class Attachment {
    public static void main(String[] args) throws IOException {
        //创建XSSFWorKbook对象
        XSSFWorkbook wb = new XSSFWorkbook("C:\\Users\\14775\\Desktop\\2102A练习表格.xls");
        //创建工作表
        XSSFSheet sheet = wb.getSheetAt(0);
        //创建行对象
        for(int i=1;i<5;i++){
            XSSFRow row = sheet.createRow(i);
            sheet.setColumnWidth(i-1,26*255);
            //创建单元格对象
            XSSFCell cell = row.createCell(0);
            //单元格赋值
            cell.setCellValue("1");
            XSSFCell cell1=row.createCell(1);
            //单元格赋值
            cell1.setCellValue("李文昊");
            XSSFCell cell2=row.createCell(2);
            //单元格赋值
            cell2.setCellValue("2102班级表");
            XSSFCell cell3=row.createCell(3);
            //单元格赋值
            cell3.setCellValue("100");
        }
        //将表格信息写入到excel文件中
        try {
            wb.write(new FileOutputStream(new File("E:\\新建文件夹\\新建 XLS 工作表.xls")));
        }catch (IOException e){
            e.printStackTrace();
        }
    }

}
